﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using microCRM.Domain;

namespace microCRM
{
    public partial class FindClient : Form
    {
        public delegate void ClientLoad(Client client);
        public event ClientLoad OnLoad;

        public FindClient()
        {
            InitializeComponent();
        }

        private void btn_Search_Click(object sender, EventArgs e)
        {
            BindingSource bindingSource = new BindingSource();
            bindingSource.DataSource = DBHelper.FindAbonent(this.txtbx_FirstName.Text, this.txtbx_MiddleName.Text,
                                                            this.txtbx_LastName.Text);
            this.dgv_Results.DataSource = bindingSource;
        }

        private void dgv_Results_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //ClientLoadEventArgs ex = new ClientLoadEventArgs(DBHelper.GetAbonentByID((int)this.dgv_Results.SelectedRows[0].Cells[0].Value));
            OnLoad(DBHelper.GetAbonentByID((int)this.dgv_Results.SelectedRows[0].Cells[0].Value));
            this.Close();
        }
    }
}
